package com.alit.ibot.robot.wechat.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alit.ibot.robot.projectvariable.PVK;
import com.alit.ibot.robot.projectvariable.ProjectVariableUtil;
import com.alit.ibot.robot.wechat.service.RobotWechatEventService;
import com.alit.ibot.robot.wechat.service.RobotWechatLocationService;
import com.alit.ibot.robot.wechat.service.RobotWechatService;
import com.alit.ibot.robot.wechat.service.RobotWechatTextService;
import com.alit.ibot.robot.wechat.service.RobotWechatVoiceService;

/**
 * @author litong
 * @date 2019年5月31日_下午12:20:36
 * @version 1.0
 * @desc
 */
@Service
public class RobotWechatServiceImpl implements RobotWechatService {
  @Autowired
  private RobotWechatTextService rwts;
  @Autowired
  private RobotWechatVoiceService rwvs;
  @Autowired
  private RobotWechatEventService rwes;
  @Autowired
  private RobotWechatLocationService rwls;

  @Override
  public String getToWechatXML(Map<String, String> requestMap) {
    String retval = ProjectVariableUtil.getValue(PVK.wechatDefaultReply); // 获取微信默认回复
    String msgType = (String) requestMap.get("MsgType"); // 获取微信消息类型
    if (msgType.equals("text")) {
      retval = this.processWechatText(requestMap); // 处理微信文本消息
      return retval;
    } else if (msgType.equals("voice")) {
      retval = this.processWechatVoice(requestMap);// 处理微信语音消息
      return retval;
    } else if (msgType.equals("event")) {
      return this.processWechatEvent(requestMap); // 处理微信事件消息
    } else if (msgType.equals("location")) {
      retval = this.processWechatLocation(requestMap); // 处理微信位置消息
    } else {
      return retval;
    }
    return retval;
  }

  private String processWechatText(Map<String, String> requestMap) {
    return rwts.getToWechatXML(requestMap);
  }

  // 获取微信消息类型
  private String processWechatVoice(Map<String, String> requestMap) {
    return rwvs.getToWechatXML(requestMap);
  }

  private String processWechatEvent(Map<String, String> requestMap) {
    return rwes.getToWechatXML(requestMap);
  }

  private String processWechatLocation(Map<String, String> requestMap) {
    return rwls.getToWechatXML(requestMap);
  }
}
